package com.wlz.rabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 *  消费者
 * @author wlz
 * @date 2022-06-29  10:12 下午
 */

@Slf4j
@Component
public class ConcumerReceiver {

    /**
     *  直连模式的多个消费者，会分到其中一个消费者进行消费。类似task模式
     *  通过注入RabbitContainerFactory对象，来设置一些属性，相当于task里的channel.basicQos
     * @param message
     */
    @RabbitListener(queues = "wlz_hello_queue")
    public void helloWorldReceive(String message) {
        log.info("wlz_hello_queue 队列 , helloworld 模式 received message : {}" , message);
    }

    /**
     *  工作队列模式
     * @param message
     */
    @RabbitListener(queues = "wlz_work_queue_1")
    public void workQueueReceive1(String message) {
        log.info("wlz_work_queue_1 队列 , 工作队列 模式 received message : {}" , message);
    }

    /**
     *  工作队列模式
     * @param message
     */
    @RabbitListener(queues = "wlz_work_queue_2")
    public void workQueueReceive2(String message) {
        log.info("wlz_work_queue_2 队列 , 工作队列 模式 received message : {}" , message);
    }

    /**
     *  发布订阅模式
     * @param message
     */
    @RabbitListener(queues = "wlz_fanout_queue_1")
    public void fanoutReceive1(String message) {
        log.info("wlz_fanout_queue_1 队列 , 发布订阅 模式 received message : {}" , message);
    }

    @RabbitListener(queues = "wlz_fanout_queue_2")
    public void fanoutReceive2(String message) {
        log.info("wlz_fanout_queue_2 队列 , 发布订阅 模式 received message : {}" , message);
    }

    /**
     *  routing 路由模式
     * @param message
     */
    @RabbitListener(queues = "wlz_direct_queue_1")
    public void directReceive1(String message) {
        log.info("wlz_direct_queue_1 队列 , 路由 模式 received message : {}" , message);
    }

    @RabbitListener(queues = "wlz_direct_queue_2")
    public void directReceive2(String message) {
        log.info("wlz_direct_queue_2 队列 , 路由 模式 received message : {}" , message);
    }

    /**
     *  topic 模式
     *   注意这个模式会有优先匹配原则。例如发送routingKey=hunan.IT,那匹配到hunan.*(hunan.IT,hunan.eco),之后就不会再去匹配*.ITd
     * @param message
     */
    @RabbitListener(queues = "wlz_topic_queue_1")
    public void topicReceive1(String message) {
        log.info("wlz_topic_queue_1 队列 , topic 模式 received message : {}" , message);
    }

    @RabbitListener(queues = "wlz_topic_queue_2")
    public void topicReceive2(String message) {
        log.info("wlz_topic_queue_2 队列 , topic 模式 received message : {}" , message);
    }



}
